package com.bite.f.controller.user;

import com.bite.common.core.constants.HttpConstants;
import com.bite.common.core.controller.BaseController;
import com.bite.common.core.domain.R;
import com.bite.f.domain.user.dto.UserDTO;
import com.bite.f.service.user.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/user")
@RestController
public class UserController extends BaseController {
    @Autowired
    private IUserService userService;
    //手机号是隐私数据，因此我们不要用get，用post好一点

    @PostMapping("/sendCode")
    public R<Void> sendCode(@RequestBody UserDTO userDTO){
        return toR(userService.sendCode(userDTO));
    }
    @PostMapping("/code/login")
    public R<String> login(@RequestBody UserDTO userDTO){
        System.out.println(userDTO);
        return R.ok(userService.login(userDTO.getPhone(),userDTO.getCode()));

    }

    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        boolean logout =  userService.logout(token);
        return toR(logout);
    }
}







































